Ext.define('cp.view.form.EspecialidadBase',{
    extend: 'Ext.form.Panel',
    
    bodyPadding: '5px 5px 5px 5px', 
    bodyStyle: 'border: none',
    fieldDefaults: {
        labelWidth: 65,
        labelAlign: 'top'
    },
    
    initComponent: function(){
        
        var action;
        
        this.items = [
            {xtype: 'textfield', fieldLabel: 'Nombre', name: 'especialidad', allowBlank: false, 
                minLength: 4, maxLength: 30, vtype: 'letrasEspacios'}
        ];
        this.callParent(arguments);
    },

    submitForm: function(){
        if(this.getForm().isValid()){
            this.sendData();
        }else{
            Ext.create('cp.view.ui.AlertErr',{
                mensaje: 'El formulario contiene errores. Por favor, corrigalos, y vuelva a realizar la operación.'
                    }).showDialog();    
        }
    },
    sendData: function(){
        var me = this;
        this.getForm().submit({
            url: me.action,
            method: 'POST',
            success: function(form,action){
                Ext.create('cp.view.ui.AlertOk',{mensaje:action.result.msg}).showDialog();
                me.up('decoratorForm').close();
                Ext.ComponentQuery.query('gestionEspecialidad')[0].getStore().load();                 
            },
            failure: function(form, action){
                Ext.create('cp.view.ui.AlertErr',{mensaje:action.result.msg}).showDialog();
            }
        });
    }

});